Matplotlib.pyplot is a state-based interface to matplotlib. It provides an implicit, MATLAB-like, way of plotting. It also opens figures on your screen, and acts as the figure GUI manager.

Average Rat Weight Per Age Table¶

Age Weight
1 1.2
2 2
3 5
4 4
In [18]:
import matplotlib.pyplot as plt

plt.figure(figsize=(10, 5))

plt.plot([0, 1, 2, 3, 4], [0,1.2, 2, 5, 4], 'g-', label='Rat Weight')

plt.title('Average Rat Weight/Age')
plt.xlabel('Rat Age')
plt.ylabel('Rat Weight')
plt.xlim(0, 5)
plt.ylim(0, 20)
plt.grid(True)
plt.legend()

plt.show()

A stem plot draws lines perpendicular to a baseline at each location locs from the baseline to heads, and places a marker there.¶

In [19]:
import numpy as np

plt.style.use('_mpl-gallery')

x = 0.5 + np.arange(8)
y = [4.8, 5.5, 3.5, 4.6, 6.5, 6.6, 2.6, 3.0]

fig, ax = plt.subplots()

ax.stem(x, y)

ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
       ylim=(0, 8), yticks=np.arange(1, 8))

plt.show()

Plotly.Express is the easy-to-use, high-level interface to Plotly, which operates on a variety of types of data and produces easy-to-style figures.¶

In [20]:
import plotly
import plotly.express as px

plotly.offline.init_notebook_mode()
df = px.data.tips()
fig = px.pie(df, values='tip', names='day')
fig.show()
3D Axes in python have an attribute in layout called scene, which contains attributes such as xaxis, yaxis and zaxis parameters, in order to set the range, title, ticks, color etc. of the axes.¶
In [21]:
import plotly.graph_objects as go
np.random.seed(1)

N = 70

fig = go.Figure(data=[go.Mesh3d(x=(70*np.random.randn(N)),
                   y=(55*np.random.randn(N)),
                   z=(40*np.random.randn(N)),
                   opacity=0.5,
                   color='green'
                  )])

fig.update_layout(
    scene = dict(
        xaxis = dict(nticks=4, range=[-100,100],),
                     yaxis = dict(nticks=4, range=[-50,100],),
                     zaxis = dict(nticks=4, range=[-100,100],),),
    width=700,
    margin=dict(r=20, l=10, b=10, t=10))

fig.show()

An Image of a Cute snoop dog as a puppy¶

In [22]:
from PIL import Image

img = Image.open('ideogram.jpeg')
fig = plt.imshow(img)
plt.axis('off')
Out[22]:
(-0.5, 1023.5, 1023.5, -0.5)